home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / cordic.lha / cordic3.code / text0000.txt < prev   
Encoding:
Text File  |  1989-10-24  |  2.8 KB  |  89 lines

  1. In article <354@abvax.UUCP> gfs@abvax.UUCP (Greg F. Shay) writes:
  2. >Ok, I'm interested.  In reply to my sin(x) in integer posting, a couple
  3. >    Could someone either thumbnail sketch the CORDIC algorithm for me
  4. >or give a reference?  Many Thanks.
  5. >
  6. >        Greg Shay
  7. >...
  8.  
  9. I looked through my references and discovered that they were fairly useless.
  10. Instead, here's some source that does ONE of the CORDIC transformations
  11. i.e. the original one, the coordinate rotation. Note that the same method
  12. generalises to do the following transformations also:
  13.  
  14. sin, cos, tan, atan, sinh, cosh, tanh, atanh, exp, ln, root.
  15.  
  16. The author of the best paper I know on this is J.S.Walther, unfortunately
  17. I can't give you the reference.
  18.  
  19. I would've mailed this but we've yet to sort our mail out...
  20.  
  21. - Paul.
  22.  
  23. -------- Cut here ---------
  24.  
  25. /* -------Forward declarations-----------------------*/
  26.  
  27. /* -------Constants and macros-----------------------*/
  28.  
  29. #define KR   107922      /* constant */
  30.  
  31. /* -------Exported variables/functions---------------*/
  32.  
  33. /* -------Imported variables/functions---------------*/
  34.  
  35. /* -------Static variables---------------------------*/
  36.  
  37. static int arctan [] =  /* Table of atans in degrees << 16 */
  38. {
  39.    2949120, 1740967, 919879, 466945,
  40.    234378, 117303, 58666, 29335,
  41.    14668, 7334, 3667, 1833,
  42.    918, 458, 229, 115
  43. };
  44.  
  45. /*                                                                *************
  46.                                                                   *           *
  47.                                                                   *  CORDIC   *
  48.                                                                   *           *
  49.                                                                   *************
  50. -------------------------------------------------------------------------------
  51. | Perform a cordic transformation on the arguments                            |
  52. | The value returned is b*cos(theta) + a*sin(theta).                          |
  53. | theta is an angle in the range 0 - 90 degrees.                              |
  54. -------------------------------------------------------------------------------
  55. */
  56. Cordic(a, b, theta)
  57. register int a, b, theta;
  58. {
  59.    register int olda, i;
  60.  
  61.    a <<= 8;
  62.    b <<= 8;
  63.    theta <<= 16;
  64.    for (i = 0; i < 16; i++)   /* do this to 16 bits */
  65.    {
  66.       olda = a >> i;
  67.       if (theta < 0)
  68.       {
  69.          a += (b >> i);
  70.          b -= olda;
  71.          theta += arctan [i];
  72.       }
  73.       else 
  74.       {
  75.          a -= (b >> i);
  76.          b += olda;
  77.          theta -= arctan [i];
  78.       }
  79.    }
  80.       /* The value returned is b*cos(theta) + a*sin(theta) */
  81.       /* a*sin(theta) if initial b was 0 */
  82.       /* b*cos(theta) if initial a was 0 */
  83.    return ((b << 8) / KR);
  84.       /* We are throwing a away, though it contains : */
  85.       /* a*cos(theta) - b*sin(theta) */
  86. }
  87.  
  88.  
  89.